<?php
namespace Home\Controller;

class UserController extends HomeController {

    public $user;

    public function _initialize(){
        parent::_initialize(); 

        if (!session('userflag')) {
            $this->redirect('Home/Login/index');
        }else{
            $crypt = new \Think\Crypt;
            $flag = $crypt->decrypt(session('userflag'),C('DATA_CRYPT_KEY'));
            $flagArr = explode(',', $flag);
            if ($flagArr[1]!=get_client_ip()) {
                $this->redirect('Home/Login/index');
            }
        }

        $user = M('Member')->where(array('id'=>$flagArr[0],'disable'=>0))->find();      
        if (!$user) {
            $this->redirect('Home/Login/index');
        }else{
            $user['money'] = $this->getUserMoney($user['id']);
            $this->user = $user;            
            $this->assign('user',$this->user);
        }
    } 
}